﻿package mortal.game.view.friend
{
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.display.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.menu.*;
    import mortal.game.view.platform.*;
    import mortal.game.view.platform.platformTencent.*;
    import mortal.mvc.core.*;

    public class FriendCellRenderer extends GCellRenderer
    {
        private var _headBorder:GBitmap;
        private var _vipImg:GImageBitmap;
        private var _headImg:GImageBitmap;
        private var _levelBorder:ScaleBitmap;
        private var _roleLevel:GTextFiled;
        private var _roleName:GTextFiled;
        private var _fightValue:GTextFiled;
        private var _roleSign:GTextFiled;
        private var _qqIcon:GImageBitmap;
        private var _closeImgArr:Array;
        private var _closeValue:int;
        private var _recordId:Number;
        private var _playerId:int;
        private var _displayObjArr:Array;
        private var _isGray:Boolean;
        private var _bmp:GBitmap;
        private var _spr:GSprite;
        private var _playerData:Object;
        public static var currSelected:FriendCellRenderer;

        public function FriendCellRenderer()
        {
            this._closeImgArr = [];
            this._displayObjArr = [];
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_2:GBitmap = null;
            super.createDisposedChildrenImpl();
            this._headBorder = UIFactory.gBitmap(ImagesConst.FriendHeadBg, 2, 1, this);
            this._displayObjArr.push(this._headBorder);
            this._headImg = UIFactory.gImageBitmap("", 3 + 2, 3 + 2, this);
            this._displayObjArr.push(this._headImg);
            this._vipImg = UIFactory.gImageBitmap("", 2, 1, this);
            this._displayObjArr.push(this._vipImg);
            this._levelBorder = UIFactory.bg(0 + 2, 25 + 2, 22, 18, this, ImagesConst.LevelBg);
            this._displayObjArr.push(this._levelBorder);
            this._roleLevel = UIFactory.gTextField("", 2 + 2, 24 + 2, 30, 20, this);
            this._displayObjArr.push(this._roleLevel);
            var _loc_1:int = 0;
            while (_loc_1 < 5)
            {
                
                _loc_2 = UIFactory.gBitmap(ImagesConst.Qinmidu_light, 193 + 17 * _loc_1, 4, this);
                this._closeImgArr.push(_loc_2);
                this._displayObjArr.push(_loc_2);
                _loc_1++;
            }
            this._roleName = UIFactory.gTextField("", 50, 0, 96, 20, this);
            this._roleName.textColor = 16761407;
            this._roleName.filters = [FilterConst.vipNameGlowFilter];
            this._displayObjArr.push(this._roleName);
            this._qqIcon = UIFactory.gImageBitmap("qqYellowYearVipSmallIcon_8", 0, 0, this);
            this._displayObjArr.push(this._qqIcon);
            this._fightValue = UIFactory.gTextField("", 216, 0, 60, 20, this);
            this._fightValue.textColor = GlobalStyle.colorChenUint;
            this._displayObjArr.push(this._fightValue);
            this._bmp = GlobalClass.getBitmap(BitmapDataConst.AlphaBMD);
            this._bmp.width = 284;
            this._bmp.height = 48;
            this._spr = UICompomentPool.getUICompoment(GSprite);
            this.addChild(this._spr);
            this._spr.buttonMode = true;
            this._spr.mouseEnabled = true;
            this._spr.addChild(this._bmp);
            this._roleSign = UIFactory.gTextField("", 50, 24, 200, 24, this);
            this._roleSign.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._displayObjArr.push(this._roleSign);
            this._spr.doubleClickEnabled = true;
            this._spr.configEventListener(MouseEvent.DOUBLE_CLICK, this.onDBClickHandler);
            return;
        }// end function

        override protected function initSkin() : void
        {
            var _loc_1:* = new GBitmap();
            var _loc_2:* = UIFactory.bg(0, 0, 282, 46, null, ImagesConst.RegionTitleBg);
            this.setStyle("downSkin", _loc_2);
            this.setStyle("overSkin", _loc_2);
            this.setStyle("upSkin", _loc_1);
            this.setStyle("selectedDownSkin", _loc_2);
            this.setStyle("selectedOverSkin", _loc_2);
            this.setStyle("selectedUpSkin", _loc_2);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:Object = null;
            var _loc_4:String = null;
            var _loc_5:String = null;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_11:Number = NaN;
            var _loc_12:int = 0;
            var _loc_13:Boolean = false;
            var _loc_14:int = 0;
            var _loc_15:int = 0;
            var _loc_16:int = 0;
            var _loc_17:int = 0;
            var _loc_18:String = null;
            super.data = param1;
            if (param1.data is SFriendRecord)
            {
                _loc_2 = param1.data as SFriendRecord;
                _loc_4 = _loc_2.friendPlayer.name;
                _loc_5 = _loc_2.friendPlayer.signature;
                _loc_6 = _loc_2.friendPlayer.camp;
                _loc_7 = _loc_2.friendPlayer.career;
                _loc_8 = _loc_2.friendPlayer.sex;
                _loc_9 = _loc_2.friendPlayer.level;
                _loc_10 = _loc_2.flag;
                _loc_11 = _loc_2.recordId;
                _loc_12 = _loc_2.friendPlayer.entityId.id;
                _loc_13 = _loc_2.friendPlayer.online;
                _loc_14 = _loc_2.friendPlayer.combat;
                _loc_15 = _loc_2.friendType;
                _loc_16 = _loc_2.friendPlayer.VIP;
                _loc_17 = _loc_2.intimate;
                _loc_18 = _loc_2.friendPlayer.proxyLevel;
            }
            else if (param1.data is SMiniPlayer)
            {
                _loc_2 = param1.data as SMiniPlayer;
                _loc_4 = _loc_2.name;
                _loc_5 = _loc_2.signature;
                _loc_6 = _loc_2.camp;
                _loc_7 = _loc_2.career;
                _loc_8 = _loc_2.sex;
                _loc_9 = _loc_2.level;
                _loc_12 = _loc_2.entityId.id;
                _loc_13 = _loc_2.online;
                _loc_14 = _loc_2.combat;
                _loc_16 = _loc_2.VIP;
                _loc_18 = _loc_2.proxyLevel;
                _loc_15 = 0;
                _loc_10 = 0;
                _loc_11 = 0;
            }
            this._playerData = _loc_2;
            this._headImg.imgUrl = AvatarUtil.getPlayerAvatarUrl(_loc_7, _loc_8, AvatarUtil.Small);
            this._roleName.text = _loc_4;
            this._roleName.x = 50;
            this._roleLevel.text = "" + _loc_9;
            if (PlatformConst.isQQ() && _loc_18)
            {
                this._qqIcon.imgUrl = PlatformTencentUtil.getQQVipIconUrl(_loc_18);
                if (PlatformTencentUtil.isYellowEnter())
                {
                    this._qqIcon.x = this._roleName.x + this._roleName.textWidth + 3;
                }
                if (PlatformTencentUtil.isBlueEnter())
                {
                    this._qqIcon.x = 50;
                    this._roleName.x = 50 + 34;
                }
            }
            else
            {
                this._qqIcon.imgUrl = "";
            }
            if (_loc_9 >= 100)
            {
                this._levelBorder.width = 30;
            }
            else
            {
                this._levelBorder.width = 21;
            }
            if (_loc_16 > 0 && _loc_16 <= 10)
            {
                this._vipImg.imgUrl = GameDefConfig.instance.getVipLevelIconUrl(_loc_16);
            }
            else
            {
                this._vipImg.imgUrl = null;
            }
            this.setTips(_loc_2);
            this.setSignature(_loc_5);
            if (_loc_10 == EFriendFlag._EFriendFlagEnemy)
            {
                this._roleSign.toolTipData = null;
                ToolTipsManager.unregister(this._spr);
            }
            this._recordId = _loc_11;
            this._playerId = _loc_12;
            this.displayByType(_loc_10);
            if (!_loc_13)
            {
                this.setGray(true);
            }
            else
            {
                this.setGray(false);
                if (_loc_16 > 0)
                {
                    this._roleName.filters = [FilterConst.vipNameGlowFilter];
                }
                else
                {
                    this._roleName.filters = [];
                }
            }
            if (_loc_10 == EFriendFlag._EFriendFlagBlackList)
            {
                this.setGray(true);
            }
            this._fightValue.text = _loc_14 + "";
            switch(_loc_10)
            {
                case EFriendFlag._EFriendFlagFriend:
                {
                    if (_loc_15 == 0)
                    {
                        PlayerMenuRegister.UnRegister(this._spr);
                        PlayerMenuRegister.Register(this._spr, _loc_2, PlayerMenuConst.FriendOpMenu);
                    }
                    else
                    {
                        PlayerMenuRegister.UnRegister(this._spr);
                        PlayerMenuRegister.Register(this._spr, _loc_2, PlayerMenuConst.IntimateFriendOpMenu);
                    }
                    break;
                }
                case EFriendFlag._EFriendFlagBlackList:
                {
                    PlayerMenuRegister.UnRegister(this._spr);
                    PlayerMenuRegister.Register(this._spr, _loc_2, PlayerMenuConst.BlackListOpMenu);
                    break;
                }
                case EFriendFlag._EFriendFlagEnemy:
                {
                    PlayerMenuRegister.UnRegister(this._spr);
                    PlayerMenuRegister.Register(this._spr, _loc_2, PlayerMenuConst.EnemyOpMenu);
                    break;
                }
                case 0:
                {
                    PlayerMenuRegister.UnRegister(this._spr);
                    PlayerMenuRegister.Register(this._spr, _loc_2, PlayerMenuConst.RecentListOpMenu);
                }
                default:
                {
                    break;
                }
            }
            var _loc_3:int = 0;
            while (_loc_3 < this._closeImgArr.length)
            {
                
                if (_loc_3 < _loc_17)
                {
                    this._closeImgArr[_loc_3].visible = true;
                }
                else
                {
                    this._closeImgArr[_loc_3].visible = false;
                }
                _loc_3++;
            }
            return;
        }// end function

        private function setGray(param1:Boolean) : void
        {
            var _loc_2:Object = null;
            if (param1 && !this._isGray)
            {
                this._isGray = true;
                for each (_loc_2 in this._displayObjArr)
                {
                    
                    _loc_2.filters = [FilterConst.colorFilter2];
                }
            }
            if (!param1 && this._isGray)
            {
                this._isGray = false;
                for each (_loc_2 in this._displayObjArr)
                {
                    
                    _loc_2.filters = [];
                }
            }
            return;
        }// end function

        private function setSignature(param1:String) : void
        {
            if (param1.length < 15)
            {
                this._roleSign.text = param1;
                if (param1 != "")
                {
                    this._roleSign.toolTipData = HTMLUtil.addColor(param1, "#FFFFFF");
                }
            }
            else
            {
                this._roleSign.text = param1.substr(0, 15) + "...";
                toolTipData = HTMLUtil.addColor(param1, "#FFFFFF");
            }
            ToolTipsManager.unregister(this._roleSign);
            ToolTipsManager.register(this._roleSign, null, toolTipData);
            return;
        }// end function

        private function setTips(param1:Object) : void
        {
            var _loc_2:String = null;
            var _loc_3:String = null;
            if (param1 is SFriendRecord)
            {
                _loc_2 = GameDefConfig.instance.getECareer(param1.friendPlayer.career).text;
                _loc_3 = "<textFormat leading=\'4\'>" + HTMLUtil.addColor(Language.getString(41217), "#ffffff") + HTMLUtil.addColor(_loc_2, "#f2de47") + "<br/>" + HTMLUtil.addColor(Language.getString(41218), "#ffffff") + HTMLUtil.addColor(param1.intimate + "", "#ffffff") + "<textFormat/>";
            }
            else if (param1 is SMiniPlayer)
            {
                _loc_2 = GameDefConfig.instance.getECareer(param1.career).text;
                _loc_3 = "<textFormat leading=\'4\'>" + HTMLUtil.addColor(Language.getString(41217), "#ffffff") + HTMLUtil.addColor(_loc_2, "#f2de47") + "<br/>" + HTMLUtil.addColor(Language.getString(41218), "#ffffff") + HTMLUtil.addColor(0 + "", "#ffffff") + "<textFormat/>";
            }
            ToolTipsManager.unregister(this._spr);
            ToolTipsManager.register(this._spr, null, _loc_3);
            return;
        }// end function

        public function displayByType(param1:int) : void
        {
            switch(param1)
            {
                case EFriendFlag._EFriendFlagFriend:
                {
                    this.friendInfoDisplay(0);
                    break;
                }
                case EFriendFlag._EFriendFlagBlackList:
                case 0:
                {
                    this.friendInfoDisplay(1);
                    break;
                }
                case EFriendFlag._EFriendFlagEnemy:
                {
                    this.friendInfoDisplay(2);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function friendInfoDisplay(param1:int) : void
        {
            var _loc_2:GBitmap = null;
            switch(param1)
            {
                case 0:
                {
                    this._fightValue.visible = false;
                    this._roleSign.visible = true;
                    for each (_loc_2 in this._closeImgArr)
                    {
                        
                        _loc_2.visible = true;
                    }
                    this._roleName.y = 0;
                    break;
                }
                case 1:
                {
                    this._fightValue.visible = false;
                    this._roleSign.visible = false;
                    for each (_loc_2 in this._closeImgArr)
                    {
                        
                        _loc_2.visible = false;
                    }
                    this._roleName.y = 10;
                    break;
                }
                case 2:
                {
                    this._fightValue.visible = true;
                    this._roleSign.visible = true;
                    for each (_loc_2 in this._closeImgArr)
                    {
                        
                        _loc_2.visible = false;
                    }
                    this._roleName.y = 0;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            event.stopImmediatePropagation();
            return;
        }// end function

        private function onDBClickHandler(event:MouseEvent) : void
        {
            event.stopImmediatePropagation();
            PlayerMenuRegister.HideOpList();
            if (this._playerData is SFriendRecord)
            {
                if ((this._playerData as SFriendRecord).flag != EFriendFlag._EFriendFlagBlackList)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ChatPrivate, this._playerData.friendPlayer));
                }
            }
            else if (this._playerData is SMiniPlayer)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ChatPrivate, this._playerData));
            }
            return;
        }// end function

        public function get recordId() : Number
        {
            return this._recordId;
        }// end function

        public function get playerId() : int
        {
            return this._playerId;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            var _loc_2:GBitmap = null;
            super.disposeImpl(param1);
            ToolTipsManager.unregister(this._roleSign);
            ToolTipsManager.unregister(this._spr);
            PlayerMenuRegister.UnRegister(this._spr);
            this._headBorder.dispose(param1);
            this._headImg.dispose(param1);
            this._vipImg.dispose(param1);
            this._levelBorder.dispose(param1);
            this._roleLevel.dispose(param1);
            for each (_loc_2 in this._closeImgArr)
            {
                
                _loc_2.dispose(param1);
                _loc_2 = null;
            }
            this._closeImgArr.length = 0;
            this._displayObjArr.length = 0;
            this._roleName.dispose(param1);
            this._fightValue.dispose(param1);
            this._roleSign.dispose(param1);
            this._spr.dispose(param1);
            this._bmp.dispose(param1);
            this._qqIcon.dispose();
            this._headBorder = null;
            this._headImg = null;
            this._vipImg = null;
            this._levelBorder = null;
            this._roleLevel = null;
            this._roleName = null;
            this._fightValue = null;
            this._roleSign = null;
            this._bmp = null;
            this._spr = null;
            this._qqIcon = null;
            this._isGray = false;
            this._closeValue = 0;
            this._recordId = 0;
            this._playerId = 0;
            return;
        }// end function

    }
}
